package com.foo.servicesCall;

import java.rmi.RemoteException;

import org.apache.axis2.AxisFault;

import com.foo.servicesCall.GetAllRestaurantDataFaultException;
import com.foo.servicesCall.GetRestaurantInfoByCusineFaultException;
import com.foo.servicesCall.GetRestaurantInfoByNameFaultException;
import com.foo.servicesCall.GetRestaurantInfoByRatingFaultException;
import com.foo.servicesCall.RestaurantServiceStub;
import com.foo.servicesCall.RestaurantServiceStub.GetAllRestaurantData;
import com.foo.servicesCall.RestaurantServiceStub.GetAllRestaurantDataResponse;
import com.foo.servicesCall.RestaurantServiceStub.GetRestaurantInfoByCusine;
import com.foo.servicesCall.RestaurantServiceStub.GetRestaurantInfoByCusineResponse;
import com.foo.servicesCall.RestaurantServiceStub.GetRestaurantInfoByName;
import com.foo.servicesCall.RestaurantServiceStub.GetRestaurantInfoByNameResponse;
import com.foo.servicesCall.RestaurantServiceStub.GetRestaurantInfoByRating;
import com.foo.servicesCall.RestaurantServiceStub.GetRestaurantInfoByRatingResponse;
import com.foo.servicesCall.RestaurantServiceStub.Restaurant;
import com.foo.servicesCall.RestaurantServiceStub.RestaurantList;

public class RestaurantWSClient {
	
	private static final String SERVICE_END_POINT = 
		"http://localhost:8080/axis2/services/RestaurantService";
	
	private RestaurantServiceStub stub;

	public RestaurantWSClient()
	{
		try
		{
			stub = new RestaurantServiceStub(SERVICE_END_POINT);
		} catch (AxisFault e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public RestaurantList getAllRestaurant()
	{
		try
		{
			GetAllRestaurantDataResponse resu = new GetAllRestaurantDataResponse();
			GetAllRestaurantData getAllRestaurantData = new GetAllRestaurantData();
			getAllRestaurantData.setIn("");
			try
			{
				resu = stub.getAllRestaurantData(getAllRestaurantData);
			}
			catch(RemoteException e)
			{
				System.out.println(e.getMessage());
			}
			catch(GetAllRestaurantDataFaultException ex)
			{
				System.out.println(ex.getMessage());
			}
			return resu.getOut();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return null;
	}
	
	public Restaurant getRestaurantInfoByName(String name)
	{
		try
		{
			GetRestaurantInfoByName res = new GetRestaurantInfoByName();
			res.setIn("Acapulco");
			GetRestaurantInfoByNameResponse result = new GetRestaurantInfoByNameResponse();

			try
			{
				result = stub.getRestaurantInfoByName(res);
			}
			catch(RemoteException e)
			{
				System.out.println(e.getMessage());
			}
			catch(GetRestaurantInfoByNameFaultException ex)
			{
				System.out.println(ex.getMessage());
			}
			
			if(result.getOut() != null)
			{
				return result.getOut();
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return null;
	}
	
	public RestaurantList getRestaurantInfoByCuisine(String cusine)
	{
		try
		{
			GetRestaurantInfoByCusine res = new GetRestaurantInfoByCusine();
			res.setIn(cusine);
			GetRestaurantInfoByCusineResponse result = new GetRestaurantInfoByCusineResponse();

			try
			{
				result = stub.getRestaurantInfoByCusine(res);
			}
			catch(RemoteException e)
			{
				System.out.println(e.getMessage());
			}
			catch(GetRestaurantInfoByCusineFaultException ex)
			{
				System.out.println(ex.getMessage());
			}
			
			if(result.getOut() != null)
			{
				return result.getOut();
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return null;
	}

	public RestaurantList getRestaurantInfoByRating(double rating)
	{
		try
		{
			GetRestaurantInfoByRating res = new GetRestaurantInfoByRating();
			res.setIn(rating);
			GetRestaurantInfoByRatingResponse result = new GetRestaurantInfoByRatingResponse();

			try
			{
				result = stub.getRestaurantInfoByRating(res);
			}
			catch(RemoteException e)
			{
				System.out.println(e.getMessage());
			}
			catch(GetRestaurantInfoByRatingFaultException ex)
			{
				System.out.println(ex.getMessage());
			}
			
			if(result.getOut() != null)
			{
				return result.getOut();
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return null;
	}
}
